﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DataAccessLayer
{
    public partial class RequestPerson
    {
        public static RequestPerson FindByRequestIDPersonID_IncludeDeleted(linqDatabaseDataContext db, int RequestID, int PersonID)
        {
            var subquery = (from u in db.RequestPersons where u.ID == (from v in db.RequestPersons where v.RequestID == u.RequestID && v.PersonID == u.PersonID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where u.RequestID == RequestID && u.PersonID == PersonID select u).SingleOrDefault());
        }

        public static RequestPerson FindByRequestIDPersonID(linqDatabaseDataContext db, int RequestID, int PersonID)
        {
            var subquery = (from u in db.RequestPersons where u.ID == (from v in db.RequestPersons where v.RequestID == u.RequestID && v.PersonID == u.PersonID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where !u.IsDeleted && u.RequestID == RequestID && u.PersonID == PersonID select u).SingleOrDefault());
        }

        public static List<RequestPerson> ToList_IncludeDeleted(linqDatabaseDataContext db)
        {
            var subquery = (from u in db.RequestPersons where u.ID == (from v in db.RequestPersons where v.RequestID == u.RequestID && v.PersonID == u.PersonID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery select u).ToList());
        }

        public static List<RequestPerson> ToList(linqDatabaseDataContext db)
        {
            var subquery = (from u in db.RequestPersons where u.ID == (from v in db.RequestPersons where v.RequestID == u.RequestID && v.PersonID == u.PersonID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where !u.IsDeleted select u).ToList());
        }

        public static List<RequestPerson> ToListByRequestID_IncludeDeleted(linqDatabaseDataContext db, int RequestID)
        {
            var subquery = (from u in db.RequestPersons where u.ID == (from v in db.RequestPersons where v.RequestID == u.RequestID && v.PersonID == u.PersonID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where u.RequestID == RequestID select u).ToList());
        }

        public static List<RequestPerson> ToListByRequestID(linqDatabaseDataContext db, int RequestID)
        {
            var subquery = (from u in db.RequestPersons where u.ID == (from v in db.RequestPersons where v.RequestID == u.RequestID && v.PersonID == u.PersonID orderby v.Timestamp descending select v).FirstOrDefault().ID select u);
            return ((from u in subquery where u.RequestID == RequestID && !u.IsDeleted select u).ToList());
        }

        public static List<RequestPerson> HistoryToListByRequestIDPersonID(linqDatabaseDataContext db, int RequestID, int PersonID)
        {
            return ((from u in db.RequestPersons where u.RequestID == RequestID && u.PersonID == PersonID select u).ToList());
        }
    }
}
